package com.noahsloan.nutils.swing;

import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 * Handy functions for dealing with Swing.
 * 
 * @author noah
 * 
 */
public class SwingUtils {

    /**
     * Attempts to set the Swing look and feel to the platforms native look and
     * feel. e.g. on Windows, it will look like a normal MS Windows window, on
     * linux, like a normal X window, etc.
     * <p>
     * This method should probably be called before any GUI is constructed, but
     * if it is not, you can apply it retroactively by calling
     * {@link SwingUtilities#updateComponentTreeUI(java.awt.Component)} one per
     * top level window (don't forget <code>window.pack()</code> afterwards!).
     * Although if something has already been drawn, this could be confusing for
     * the user.
     * 
     * @return the previous look and feel (if successful) or null if setting the
     *         look and feel failed for some reason.
     */
    public static LookAndFeel setNatitiveLookAndFeel() {
        LookAndFeel old = UIManager.getLookAndFeel();
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            return null;
        }
        return old;
    }

}
